package com.boco.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.dao.GetEMR_ZYYZData;
import com.boco.dao.SentData;
import com.boco.entity.EMR_ZYYZ;

public class InsertEMR_ZYYZDataAction {
	private static final Log log = LogFactory.getLog(InsertEMR_ZYYZDataAction.class);
	public  String insertData(){
		String url = "http://fasong.cdxp.csb/json/dzbl4";
		String resule = null;
		List<EMR_ZYYZ> list = new ArrayList<EMR_ZYYZ>();
		list = GetEMR_ZYYZData.getData();
		
	    log.info("########################################");
	    log.info("数据总条数："+list.size());
	    log.info("########################################");
		String userName = "dzbl4";
		String password = "322dfbf9048445cabb06cbf24e64cdcf";
		EMR_ZYYZ temp = null;
		
		for(int i=0;i<list.size();i++){
			String param = null;
			temp = list.get(i);
			//log.info(temp.getXM());
			//按照身份证删除已经存在的值。
			param = "{\"SQL\":\"delete  EMR_ZYYZ where ZYH='"+
					temp.getZYH()
					+"' and YLJGZZJGDM = '"+temp.getYLJGZZJGDM()+"'"
			
					+ "\", \"ANNOTION\":\"cdxplogs\"}";
			resule = SentData.sendPost(url, param, userName, password);
			log.info("删除结果："+resule);
			param = "{\"SQL\":\"INSERT INTO EMR_ZYYZ ("
					+ "HZZSYH,"
					+ "YLJGZZJGDM,"
					+ "YLJGMC,"
					+ "ZYH,"
					+ "XM,"
					+ "XB,"
					+ "NL,"
					+ "TZ,"
					+ "BQMC,"
					+ "KSDM,"
					+ "KSMC,"
					+ "BFH,"
					+ "BCH,"
					+ "YZBH,"
					+ "YZXH,"
					+ "XMBM,"
					+ "XMMC,"
					+ "DZSQDBH,"
					+ "SFXM,"
					+ "YZKLRQSJ,"
					+ "YZKLZGH,"
					+ "YZKLZQM,"
					+ "YZKLKSDM,"
					+ "YZKLKS,"
					+ "YZJHKSSJ,"
					+ "YZJHJSSJ,"
					+ "YZXMLX,"
					+ "YZBZXX,"
					+ "YZSHRGH,"
					+ "YZSHRQM,"
					+ "SHRQSJ,"
					+ "HDHSGH,"
					+ "HDHSQM,"
					+ "HSHDSJ,"
					+ "YZZXRQSJ,"
					+ "ZXYZZGH,"
					+ "ZXYZZQM,"
					+ "YZZXKSDM,"
					+ "YZZXKS,"
					+ "YZZXZT,"
					+ "YZTZRQSJ,"
					
					+ "TZYZZGH,"
					+ "TZYZZQM,"
					+ "YZSJSX,"
					+ "USE_WAY,"
					+ "USE_WAY_NAME,"
					+ "YZPL,"
					+ "YZPL_CS,"
					+ "YZPL_JE,"
					+ "YZPL_JEDW,"
					+ "DURATION,"
					+ "DURATION_UNIT,"
					+ "TRANSFUSION_SPEED,"
					+ "TRANSFUSION_UNIT,"
					+ "SINGLE_DOSE,"
					+ "SINGLE_DOSE_UNIT,"
				

					+ "ZRLSH,"
					+ "BCRQ,"
					+ "ORGCODE,"
					+ "AREACODE,"
					+ "UPLOADTIME,"
					+ "SOURCEID"
					+ ") VALUES("
					+ "'" + checkStr(temp.getHZZSYH()) + "'," 
					+ "'" + checkStr(temp.getYLJGZZJGDM()) + "'," 
					+ "'" + checkStr(temp.getYLJGMC()) + "'," 
					+ "'" + checkStr(temp.getZYH()) + "'," 
					+ "'" + checkStr(temp.getXM()) + "',"
					+ "'" + checkStr(temp.getXB()) + "'," 
					+ "'" + checkStr(temp.getNL()) + "'," 
					+ "'" + checkStr(temp.getTZ()) + "'," 
					+ "'" + checkStr(temp.getBQMC()) + "'," 
					+ "" + checkStr(temp.getKSDM()) + "," 
					+ "'" + checkStr(temp.getKSMC()) + "'," 
					+ "'" + checkStr(temp.getBFH()) + "',"
					+ "'" + checkStr(temp.getBCH()) + "',"
					+ "'" + checkStr(temp.getYZBH()) + "'," 
					+ "'" + checkStr(temp.getYZXH()) + "'," 
					+ "'" + checkStr(temp.getXMBM()) + "'," 
					+ "'" + checkStr(temp.getXMMC()) + "'," 
					+ "'" + checkStr(temp.getDZSQDBH()) + "'," 
					+ "'" + checkStr(temp.getSFXM()) + "'," 
					+ "to_date('" + checkStr(temp.getYZKLRQSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					
					
					+ "" + checkStr(temp.getYZKLZGH()) + "," 
					+ "'" + checkStr(temp.getYZKLZQM()) + "'," 
					+ "'" + checkStr(temp.getYZKLKSDM()) + "',"
					+ "'" + checkStr(temp.getYZKLKS()) + "',"
					+ "'" + checkStr(temp.getYZJHKSSJ()) + "'," 
					+ "'" + checkStr(temp.getYZJHJSSJ()) + "'," 
					+ "'" + checkStr(temp.getYZXMLX()) + "'," 
					+ "'" + checkStr(temp.getYZBZXX()) + "'," 
					+ "'" + checkStr(temp.getYZSHRGH()) + "'," 
					+ "'" + checkStr(temp.getYZSHRQM()) + "'," 
					+ "to_date('" + checkStr(temp.getSHRQSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "'" + checkStr(temp.getHDHSGH()) + "'," 
					+ "'" + checkStr(temp.getHDHSQM()) + "'," 
					+ "to_date('" + checkStr(temp.getHSHDSJ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "to_date('" + checkStr(temp.getYZZXRQSJ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "'" + checkStr(temp.getZXYZZGH()) + "'," 
					+ "'" + checkStr(temp.getZXYZZQM()) + "'," 
					+ "'" + checkStr(temp.getYZZXKSDM()) + "'," 
					+ "'" + checkStr(temp.getYZZXKS()) + "'," 
					+ "'" + checkStr(temp.getYZZXZT()) + "'," 
					+ "to_date('" + checkStr(temp.getYZTZRQSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					
					+ "'" + checkStr(temp.getTZYZZGH()) + "'," 
					+ "'" + checkStr(temp.getTZYZZQM()) + "',"
					+ "'" + checkStr(temp.getYZSJSX()) + "'," 
					+ "'" + checkStr(temp.getUSE_WAY()) + "'," 
					+ "'" + checkStr(temp.getUSE_WAY_NAME()) + "'," 
					+ "'" + checkStr(temp.getYZPL()) + "'," 
					+ "'" + checkStr(temp.getYZPL_CS()) + "'," 
					+ "'" + checkStr(temp.getYZPL_JE()) + "'," 
					+ "'" + checkStr(temp.getYZPL_JEDW()) + "'," 
					+ "'" + checkStr(temp.getDURATION()) + "',"
					+ "'" + checkStr(temp.getDURATION_UNIT()) + "'," 
					+ "'" + checkStr(temp.getTRANSFUSION_SPEED()) + "'," 
					+ "'" + checkStr(temp.getTRANSFUSION_UNIT()) + "'," 
					+ "'" + checkStr(temp.getSINGLE_DOSE()) + "'," 
					+ "'" + checkStr(temp.getSINGLE_DOSE_UNIT()) + "'," 
					
					
					+ "'" + checkStr(temp.getZRLSH()) + "'," 
					+ "to_date('" + checkStr(temp.getBCRQ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "'" + checkStr(temp.getORGCODE()) + "'," 
					+ "'" + checkStr(temp.getAREACODE()) + "'," 
					+ "sysdate," 
					+ "'dzbl4'" 
					+ ")\", \"ANNOTION\":\"cdxplogs\"}";
					resule = SentData.sendPost(url, param, userName, password);
					log.info(resule);
					
		}
		log.info("上传完成！");
		return resule;
		
	
		
	}
	
	public static String checkStr(Object obj){
		if (obj== null){
			obj = "";
		}
		return (String) obj;
	}
	
	
}
